﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

using System.Net;

namespace Chapter26.DnsLookup
{
    /// <summary>
    /// DnsLookupWindow.xaml 的交互逻辑
    /// </summary>
    public partial class DnsLookupWindow : Window
    {
        public DnsLookupWindow()
        {
            InitializeComponent();
        }

        private void submitButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                var ipHost = Dns.GetHostEntry(hostNameTextBox.Text);
                foreach (var ip in ipHost.AddressList)
                {
                    var ipAddress = ip.AddressFamily.ToString();
                    ipAddessListBox.Items.Add(ipAddress);
                    ipAddessListBox.Items.Add(ip.ToString());
                }
                hostNameResoleTextBox.Text = ipHost.HostName;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}
